And surely, she romantically desired him, and he would have inclined to her if he had not seen the Proof from his Lord; just like that We averted evil and shameful deeds from him, indeed he was among Our chosen sincere servants.
The Proof, Wisdom, and Knowledge mentioned in this verse is Adhikr. All 313 Messengers are sent with Adhikr-the Trust and Proof- as explained in verse 11: 50. The heedful will not do evil even if he gets a chance to do so by seeing Lord through Adhikr-the Best Book. It is told in verses 15: 39-40; 37: 40 and 38: 82-83: "Satan will entrap mankind by showing them the alluring life on Earth and will make them aimless about life except those who live only for serving Lord and who are sincere servants of Lord". It is told in verse 19: 51 that Moses was a sincere Prophet and Messenger of Lord. See explanation 2: 139; 4: 118 and 11: 118-119.